/*
 * @lc app=leetcode.cn id=806 lang=javascript
 *
 * [806] 写字符串需要的行数
 */

// @lc code=start
/**
 * @param {number[]} widths
 * @param {string} s
 * @return {number[]}
 */
var numberOfLines = function(widths, s) {
  if(s.length === 0) return 0;
  let currentWidth = 0;
  let lines = 1;
  s.split('').forEach(word=>{
    let width = widths[word.charCodeAt() - 'a'.charCodeAt()];
    if(currentWidth + width > 100) {
      currentWidth = width;
      lines++;
    } else {
      currentWidth += width;
    }
  })
  return [lines, currentWidth];
};
// @lc code=end
